import { Login } from '@/model/login/Login';
import { useInjectable } from '@/unit/hooks/use-di';
import { NavigateTo } from '@/unit/navigate-to';
import Taro from '@tarojs/taro';
import { observer } from 'mobx-react-lite';
import React, { useCallback } from 'react';
import LoginView from './loginView';

export default observer(() => {
  const login = useInjectable(Login);

  const handleAdd = () => {
    // login.add();
  };

  const handleTo = () => {
    // NavigateTo('home');
    Taro.login({
      success: (res) => {
        console.log('res', res);
      },
    });
  };

  const goRegister = () => {
    NavigateTo('register');
  };

  const handleLogin = useCallback(() => {
    login.login();
  }, [login]);

  return (
    <LoginView
      handleLogin={handleLogin}
      setPassword={login.setPassword}
      goRegister={goRegister}
      setName={login.setName}
      count={login.count}
      add={handleAdd}
      go={handleTo}
    />
  );
});
